#!/bin/csh
set ZONE = 19
set MERIDIAN = `echo $ZONE | awk '{print int((('$ZONE'*6)-180)-3)}'`
set UTM_REGION = `echo $MERIDIAN| awk '{printf("%i/%i/%i/%i\n", $1-3,$1+3,-90,0)}' `

foreach t (01 04 13 15 16A 17 23 25 11 32) #add num of lines here
    set input_txt = MGL1610MC"$t"_geometry_grd_rot_crooked.axon_MC"$t"cmp_xy_m.txt
    #echo $input_txt
    set linenum = MC"$t"
    ##############  UTM to GEOGRAPHICAL coordiante ####################################
    awk '{if(NR>=1) printf("%.12lg %.12lg %d \n",$2,$3,$1)}' $input_txt | \
    gmt mapproject -V -I -Ju$ZONE/1:1 -R$UTM_REGION -C0/0 -F | \
    awk '{printf("%d %.12lg %.12lg \n",$3,$1,$2)}' > MGL1610_geometry_grd_rot_crooked.axon_cmp_xy_m_$linenum.latlong
    ################## Grid data track via seismic line ##############################
    awk '{printf("%.12lg %.12lg %d %d \n",$2,$3,$1,$1)}' MGL1610_geometry_grd_rot_crooked.axon_cmp_xy_m_$linenum.latlong > tmp.txt
    gmt grdtrack tmp.txt -Goutput.grd -h > geo_coor_cdp_$linenum.txt
    ############## geographical to utm coordinate and rearrange,rearrange means arrange the column ######################
    awk '{if(NR>1) printf("%.12lg %.12lg %.12lg %.12lg %d %d %.12lg \n",$1,$2,$1,$2,$3,$4,$5*-1)}' geo_coor_cdp_$linenum.txt | \
    gmt mapproject -Ju$ZONE/1:1 -R$UTM_REGION -C0/0 -F | \
    awk '{printf("%d %d %.12lg %.12lg %.12lg %.12lg %.12lg \n",$5,$6,$1,$2,$3,$4,$7)}' > utm_latlong_cdp_bathydepth_full_length_$linenum.txt
end

rm -f gmt*